﻿<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html>
<!-- saved from url=(0033)http://research.microsoft.com/pex -->
<head><link rel="StyleSheet" href="er.common.css" type="text/css" /><script src="er.common.js" type="text/javascript"> </script><link rel="SHORTCUT ICON" href="favicon.ico" /><link rel="icon" href="favicon.ico" type="image/x-icon" /><title>C:\Users\AO\Documents\Visual Studio 2010\AutomaTones3\automatones\AutomaTones\AutomaTones\HW Sense Compute\ConnectVirtualMidi.cs</title></head><body><div class="banner"></div><h2 id="top">C:\Users\AO\Documents\Visual Studio 2010\AutomaTones3\automatones\AutomaTones\AutomaTones\HW Sense Compute\ConnectVirtualMidi.cs</h2><div class="toggle"><p class="copyright"><a class="usercodeundertestcovered">user code under test</a>, 
  <span class="usercodeundertestnotcovered">user code under test (not covered)</span>, 
  <a class="userortestcodecovered">user code or test</a>, 
  <span class="userortestcodenotcovered">user code or test (not covered)</span>,
  <span class="tagged">tagged</span></p><table><tr><th>Methods</th></tr><tr><th /></tr></table><div class="toggle"><a class="button" href="#ID0EL">first</a><pre class="coverage">using System;
using Midi;
using Microsoft.Pex.Framework;

namespace AutomaTones.HW_Sense_Compute {
    /// &lt;summary&gt;
    /// Handles the setup of the Virtual Midi driver needed to communicate from our program to the other application handling sound.
    /// &lt;/summary&gt;
    /// &lt;author&gt;Anders Bech Mellson, anbh@itu.dk&lt;/author&gt;
    [PexClass]
    partial class ConnectVirtualMidi : IConnect
    {
        public static OutputDevice Out;

        int? _outDevice;
        const String Error = "No Virtual Midi driver present. Have you installed the driver?";
        
        <span id="ID0EL"><a class="button" href="#top">top</a>|<a class="button" href="#ID0E3D">next</a></span><a class="userortestcodecovered">public ConnectVirtualMidi()</a> <a class="userortestcodecovered">{</a>
            <a class="userortestcodecovered">Out = OutputDevice.InstalledDevices[GetOutDeviceNumber()];</a>
        <a class="userortestcodecovered">}</a>

        /// &lt;summary&gt;
        /// Is the Virtual Midi driver connected?
        /// &lt;/summary&gt;
        [PexMethod]
        public bool Connected() {
            return Out != null;
        }

        /// &lt;summary&gt;
        /// Scans through the connected output devices and sets _outDevice to match the one containing the LoopBe (Virtual Midi Driver).
        /// &lt;/summary&gt;
        private void SetOutDeviceNumber() <a class="button" href="#ID0EL">prev</a>|<span id="ID0E3D"><a class="button" href="#top">top</a>|<a class="button" href="#ID0ELIAC">next</a></span><a class="userortestcodecovered">{</a>
            <a class="userortestcodecovered">if (OutputDevice.InstalledDevices.Count == 0)</a> <span class="userortestcodenotcovered">{</span>
                <span class="userortestcodenotcovered">throw new System.ArgumentException(Error);</span>
            }
            <a class="userortestcodecovered">int i = 0;</a>
            <a class="userortestcodecovered">foreach</a> (<a class="userortestcodecovered">OutputDevice device</a> <a class="userortestcodecovered">in</a> <a class="userortestcodecovered">OutputDevice.InstalledDevices</a>) <a class="userortestcodecovered">{</a>
                <a class="userortestcodecovered">if (device.Name.Contains("LoopBe"))</a> <a class="userortestcodecovered">{</a>
                    <a class="userortestcodecovered">_outDevice = i;</a>
                    <a class="userortestcodecovered">break;</a>
                }
                <a class="userortestcodecovered">i++;</a>
            <a class="userortestcodecovered">}</a>
        <a class="userortestcodecovered">}</a>

        /// &lt;summary&gt;
        /// Tries to get the outDevice int. Throws an exception that is handled by MainController if no Virtual Midi driver is connected.
        /// &lt;/summary&gt;
        private int GetOutDeviceNumber() <a class="button" href="#ID0EL">prev</a>|<span id="ID0ELIAC"><a class="button" href="#top">top</a></span><a class="userortestcodecovered">{</a>
            <a class="userortestcodecovered">SetOutDeviceNumber();</a>
            <a class="userortestcodecovered">if (_outDevice == null)</a>
                <span class="userortestcodenotcovered">throw new System.ArgumentException(Error);</span>
            <a class="userortestcodecovered">return (int)_outDevice;</a>
        <a class="userortestcodecovered">}</a>
    }
}
</pre></div></div><hr /><table width="100%"><tr><td valign="top"><span class="copyright">Copyright (c) Microsoft Corporation. All rights reserved.</span><br /><span class="button" onclick="copySourceToClipboard()">Copy full source to clipboard</span></td></tr></table><div id="debugdiv"> </div></body></html>